; ORIGINAL: 3dt2.1/examples/flythru.scm
; $Id: flythru.scm,v 1.4 1997/04/30 20:24:11 jread Exp $
;- flythru.scm ----------------------------------------------------
; Fly a view along a curve
;------------------------------------------------------------------
; Create a view for display output
(view:dl 0 0 500 350)
(view:set-perspective #t)

; Create some geometry to fly through: a block with a hole in it
(define block (solid:block (position -50 -50 -50) (position 50 50 0)))
(define cone (solid:cone (position 0 -50 0) (position 0 50 0) 30 5))
(solid:subtract block cone)

; Create a flight path through the hole in the block using a spline
(define path
  (edge:spline
    (list (position 0 -200 30)
          (position 0 -130 20)
          (position 0 -60 5)
          (position 0 -40 0)
          (position 0 0 0)
          (position 0 50 0))))

; Define a procedure which takes a single step along a curve
(define video-step
  (lambda (frame nframe dist)
    (let* (
            (t  (/ frame nframe))
            (ep (curve:eval-pos path t))
            (ed (gvector:scale (gvector:unitize (curve:eval-tan path t)) dist)))
      (view:set-eye ep)
      (view:set-target (position:offset ep ed))
      (view:refresh))))

; Define an animation procedure which loops through a number of frames
; nframe is number of frames generated along the curve
; dist is the distance traveled along the curve for each new frame
(define video-play
  (lambda ()
    (let* (
            (nframe 500)
            (dist 10))
      (view:set-perspective #t)
      (do
        ((icnt 1 (+ icnt 1)))
        ((> icnt nframe))
        (video-step icnt nframe dist)))))

; Perform the animation
(video-play)
